<template>
  <el-dialog :title="type === 'insert' ? '新增要点' : '修改要点'" :visible.sync='visible' width='600px'
             @closed='closeDialog'>
    <el-row>
      <el-col :span='7'>
        <span class='label'>所属分类<em style='color: red'>*</em></span>
      </el-col>
      <el-col :span='17'>
        <el-input v-model="examOutlineDetail.parentName" disabled/>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span='7'>
        <span class='label'>要点名称<em style='color: red'>*</em></span>
      </el-col>
      <el-col :span='17'>
        <el-input v-model="examOutlineDetail.name" placeholder="请输入要点名称"/>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span='7'>
        <span class='label'>要求<em style='color: red'>*</em></span>
      </el-col>
      <el-col :span='17'>
        <el-input v-model="examOutlineDetail.requireValue" placeholder="请输入要求"/>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span='7'>
        <span class='label'>科目<em style='color: red'>*</em></span>
      </el-col>
      <el-col :span='17'>
        <el-input v-model="examOutlineDetail.subjectValue" placeholder="请输入科目"/>
      </el-col>
    </el-row>

    <div slot="footer" class="dialog-footer">
      <el-button @click='visible = false'>取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'InsertDetailDialog',
  data() {
    return {
      type: '',
      visible: false,
      examOutlineDetail: {
        name: '',
        requireValue: '',
        subjectValue: ''
      }
    }
  },
  methods: {
    async submit() {
      // 校验;
      if (UTIL.isEmpty(this.examOutlineDetail.name)) {
        this.$message.warning("要点名称不能为空")
        return
      }
      if (UTIL.isEmpty(this.examOutlineDetail.requireValue)) {
        this.$message.warning("要求不能为空")
        return
      }
      if (UTIL.isEmpty(this.examOutlineDetail.subjectValue)) {
        this.$message.warning("科目不能为空")
        return
      }
      // 校验新增/编辑的要点名称是否重复
      await this.axios.get('/pmph/action/examOutline/selectDetailName', {
        params: this.examOutlineDetail
      }).then((response) => {
        if (this.type === 'insert') {
          this.examOutlineDetail.sort = response.data;
        }
      });

      this.axios.post('/pmph/action/examOutline/saveDetail', this.examOutlineDetail).then(() => {
        this.$emit('saveDetail')
      })
      this.closeDialog();
    },
    closeDialog() {
      this.visible = false
      this.examOutlineDetail.id = ''
      this.examOutlineDetail.examOutlineId = ''
      this.examOutlineDetail.examOutlineTagId = ''
      this.examOutlineDetail.name = ''
      this.examOutlineDetail.sort = null
      this.examOutlineDetail.requireValue = ''
      this.examOutlineDetail.subjectValue = ''
      this.examOutlineDetail.knowledgeNum = null
      this.examOutlineDetail.exerciseNum = null
      this.examOutlineDetail.source = null
      this.examOutlineDetail.sort = null
    }
  },
}
</script>

<style scoped>
.el-row {
  line-height: 50px;
}

.el-col {
  display: inline-block;
}

/deep/ .el-dialog__body {
  padding: 0px 20px;
}
</style>
